<template>
	<view class="container">
		<view class="group-box">
			<view v-for="(item,index) in listData" :key="index" class="delivery-list">
				<view class="head-box">
					<text class="code">{{item.expressCode}}</text>
					<text class="text">{{item.express.title}}</text>
				</view>
				<view class="goods-box" 
					v-for="(goodsItem, goodsIndex) in item.deliveryGoods" 
					:key="goodsIndex">
					<view @click.stop="linkUrl('../goods/show?id='+goodsItem.orderGoods.goodsId)" class="img-box">
						<image mode="widthFix" :src="$api.loadFile(goodsItem.orderGoods.imgUrl)"></image>
					</view>
					<view class="right">
						<text class="title">{{goodsItem.orderGoods.goodsTitle}}</text>
						<text class="attr">{{goodsItem.orderGoods.skuText}}  x {{goodsItem.orderGoods.quantity}}</text>
						<text class="price">{{goodsItem.orderGoods.realPrice}}</text>
					</view>
				</view>
				<view class="content-box">
					<view v-if="item.options&&item.options.length===0" @click="loadExpress(item)" class="more">
						<text class="text">显示物流信息</text>
						<text class="icon iconfont icon-arrow-left"></text>
					</view>
					<uni-steps :options="item.options" direction="column" :active="0"></uni-steps>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				listData: [],
			}
		},
		methods: {
			async initData(no){
				let _this = this;
				//正在加载
				uni.showLoading({
				    title: '加载中'
				});
				await _this.$api.request({
					url: `/account/order/delivery/${no}`,
				}).then(res=>{
					//console.log(res.data)
					_this.listData = res.data;
				});
				_this.listData.forEach(item=>{
					_this.$set(item, 'options', []);
				});
				//关闭加载
				uni.hideLoading();
			},
			//加载物流信息
			async loadExpress(item){
				let _this = this;
				await _this.$api.request({
					url: `/account/order/delivery/express/${item.id}`,
				}).then(res=>{
					//console.log(res.data);
					if(res.data.message!="ok"){
						item.options.push({
							title: "物流查询出错，请联系管理员"
						})
						return;
					}
					//增加物流列表
					res.data.data.forEach(val=>{
						item.options.push({
							title: val.context,
							desc: val.time
						})
					});
				});
			}
		},
		onLoad(options){
			this.initData(options.no);
		}
	}
</script>

<style lang="scss">
	.delivery-list{
		display: flex;
		flex-direction: column;
		margin-bottom: 24rpx;
		border-radius: 20rpx;
		background: #fff;
		.head-box{
			display: flex;
			align-items: center;
			position: relative;
			padding: 0 30rpx;
			height: 80rpx;
			color: #333;
			font-size: 28rpx;
			.code{
				flex: 1;
			}
			.text{
				color: #999;
			}
		}
		.goods-box{
			display: flex;
			padding: 20rpx 0 20rpx 30rpx;
			border-top: 2rpx solid #f5f5f5;
			.img-box{
				display: flex;
				align-items: center;
				box-sizing: border-box;
				padding: 2rpx;
				width: 136rpx;
				height: 136rpx;
				border-radius: 20rpx;
				background: #f5f5f5;
				image{
					border-radius: 20rpx;
					width: 100%;
				}
			}
			.right{
				flex: 1;
				display: flex;
				flex-direction: column;
				padding: 0 30rpx 0 24rpx;
				overflow: hidden;
				.title{
					font-size: 30rpx;
					color: #333;
					line-height: 1;
					white-space: nowrap;
					text-overflow: ellipsis;
					overflow: hidden;
				}
				.attr{
					color: #999;
					font-size: 26rpx;
					line-height: 1;
					padding: 20rpx 0;
					white-space: nowrap;
					text-overflow: ellipsis;
					overflow: hidden;
				}
				.price{
					color: #333;
					font-size:30rpx;
					line-height: 1;
					&:before{
						content: '￥';
						font-size: 24rpx;
					}
				}
			}
		}
		.content-box{
			padding: 24rpx;
			border-top: 2rpx solid #f5f5f5;
			.more{
				display: flex;
				flex-direction: column;
				text-align: center;
				color: #999;
				font-size: 24rpx;
				line-height: 1;
				.text{
					margin-bottom: 6rpx;
				}
				.icon{
					margin: auto;
					display:inline-block;
					width: 24rpx;
					height: 24rpx;
					color: #ccc;
					font-size: 24rpx;
					transform: rotate(-90deg);
				}
			}
			
		}
	}
</style>
